﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace QuiddichWPF
{
    /// <summary>
    /// Logique d'interaction pour BarUserControl.xaml
    /// </summary>
    public partial class BarUserControl : UserControl
    {
        public BarUserControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Déclanché lors du clic sur le bouton de fermeture
        /// </summary>
        /// <param name="sender"> Sender object </param>
        /// <param name="e"> Arguments </param>
        private void quitApp_MouseClick(object sender, RoutedEventArgs e)
        {
            Window.GetWindow(this).Close();            
        }

        /// <summary>
        /// Déclanché lors du clic sur le bouton de maximisation de la fenêtre
        /// </summary>
        /// <param name="sender"> Sender object </param>
        /// <param name="e"> Arguments </param>
        private void maximizeWin_MouseClick(object sender, RoutedEventArgs e)
        {
            if (Window.GetWindow(this).WindowState == System.Windows.WindowState.Maximized)
            {
                Window.GetWindow(this).WindowState = WindowState.Normal;
            }
            else
            {
                Window.GetWindow(this).WindowState = WindowState.Maximized;
            }
        }

        private void Home_MouseClick(object sender, RoutedEventArgs e)
        {
            if (Application.Current.MainWindow == null)
            {
                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
            }
            else
            {
                Application.Current.MainWindow.Activate();
            }
        }

        private void Button_MouseEnter(object sender, MouseEventArgs e)
        {
            Canvas canvas = sender as Canvas;
            ((canvas.Children[0]) as Rectangle).Stroke = Brushes.Black;
        }

        private void Button_MouseLeave(object sender, MouseEventArgs e)
        {
            Canvas canvas = sender as Canvas;
            ((canvas.Children[0]) as Rectangle).Stroke = Brushes.White;
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (Application.Current.MainWindow != null)
            {
                if (Application.Current.MainWindow.Equals((Window)PresentationSource.FromVisual(this).RootVisual))
                    home.Visibility = System.Windows.Visibility.Collapsed;
                else
                    home.Visibility = System.Windows.Visibility.Visible;
            }
        }
    }
}
